package org.cars.server.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author caoqianfan
 * @date 2024/3/14 14:54
 */
@RestController
@Slf4j
public class Hello {
    @GetMapping("/hello")
    public String sayHello() {
        return "Hello Forest!";
    }

    @PostMapping("/setTwoParams")
    public ResponseEntity<String> setParams(@RequestParam("name") String name, @RequestParam("phone") String phone, @RequestParam("ps") Integer ps) {
        if (1 == ps) {
            return ResponseEntity.status(500).body("set fail!");
        } else if (2 == ps) {
            throw new RuntimeException("find an exception!");
        }
        log.info("set params: name={}, phone={}", name, phone);
        return ResponseEntity.ok("set success!");
    }
}
